import echarts from 'echarts';
/**
 * echart 初始化通用方法
 */
export default (config, chartID) => {
  // console.log("chartID",echarts.getInstanceByDom(document.getElementById(chartID)))
  let myChart = echarts.getInstanceByDom(document.getElementById(chartID));
  let radarTip = document.getElementById('leida-top');

  // let radarTip = echarts.getInstanceByDom(document.getElementById("leida-top"));

  if (myChart === undefined) {
    myChart = echarts.init(document.getElementById(chartID));
  }

  // myChart.setOption(config);

  if (chartID === 'radarChart') {
    // $("#total-score").html(complex.score + '&nbsp;&nbsp;<img src="${ctx}/static/img/home'+ complex.score_flag +'.png"/>');
    // $("#samecompany").html(complex.industry_rank);

    myChart.setOption(config);

    myChart.on('mouseover', function(params) {
      console.log('params === ', params);
      // let radarTip = echarts.getInstanceByDom(document.getElementById("leida-top"));
      // console.log('radarTip',radarTip)
      // var $leida = ("#leida-top");
      let _data = JSON.parse(sessionStorage.getItem('radarContent'));
      radarTip.style.display = 'block';
      // radarTip.css("top",params.event.offsetX + 10);
      // radarTip.css("left",params.event.offsetY + 10);
      if (params.name.trim() === '合规') {
        console.log('合规');
        radarTip.style.top = params.event.offsetY + 'px';
        radarTip.style.left = params.event.offsetX + 'px';
        radarTip.innerHTML = _data.compliance.content;
        // this.props.transferTip(true)
        // radarTip.html('<p>合规</p>');
        // leida.show();
      } else if (params.name === '市场') {
        console.log('市场');
        radarTip.style.top = params.event.offsetY + 'px';
        radarTip.style.left = params.event.offsetX + 'px';
        radarTip.innerHTML = _data.market.content;
        // radarTip.html('市场');
        // leida.show();
      } else if (params.name === '形象') {
        console.log('形象');
        radarTip.style.top = params.event.offsetY + 'px';
        radarTip.style.left = params.event.offsetX + 'px';
        radarTip.innerHTML = _data.opinion.content;
        // radarTip.html('形象');
        // leida.show();
      } else if (params.name === '经营') {
        console.log('形象');
        radarTip.style.top = params.event.offsetY + 'px';
        radarTip.style.left = params.event.offsetX - 200 + 'px';
        radarTip.innerHTML = _data.manage.content;
        // radarTip.html('经营');
        // leida.show();
      }
    });

    myChart.on('mouseout', function(params) {
      radarTip.style.display = 'none';
      // $("#leida-top").hide();
    });
  } else {
    myChart.setOption(config);
  }

  window.addEventListener('resize', () => {
    // console.log("屏幕宽度：", window.innerWidth)
    myChart.resize();
  });
};
